interface SiteConfig {
  baseUrl: string
  chaptersUrl?: string
  novelId: string
  getNovelUrl: () => string
  getChaptersUrl: () => string
}

interface ParserConfig {
  title: string
  author: string
  description: string
  cover: string
  chapterList: string
  chapterTitle: string
  chapterContent: string
}

export const config = {
  storage: {
    basePath: process.env.NOVEL_STORAGE_PATH ?? './novels',
  },

  request: {
    delayTime: Number(process.env.NOVEL_DELAY_TIME) || 2000,
    retryDelayMultiplier: 3,
    headers: {
      'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
      'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
      'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8'
    },
    timeout: 10_000,
  },

  sites: {
    zongheng: {
      baseUrl: 'https://www.zongheng.com/detail/{novelId}',
      chaptersUrl: 'http://book.zongheng.com/showchapter/{novelId}.html',
      novelId: '431658',
      getNovelUrl() {
        return this.baseUrl.replace('{novelId}', this.novelId)
      },
      getChaptersUrl() {
        if (this.chaptersUrl)
          return this.chaptersUrl.replace('{novelId}', this.novelId)
        else
          return "";
      }
    } satisfies SiteConfig
  },

  parser: {
    zongheng: {
      title: '#__layout > section > section > section > section:nth-child(1) > section > section > section.detail-top--main-content > section.book-info > div:nth-child(2) > div.book-info--title > span',
      author: '#__layout > section > section > section > section:nth-child(1) > section > section > section.detail-top--main-content > section.author-info > a.author-info--name',
      description: 'meta[name="description"]',
      cover: '#__layout > section > section > section > section:nth-child(1) > section > section > section.detail-top--main-content > section.book-info > div.book-info--coverImage.global-book--shadow > div.book-info--coverImage-cover.global-book--frame > img.animation-img.book-info--coverImage-img',
      chapterList: '.chapter-list a',
      chapterTitle: '.chapter-title, .title',
      chapterContent: 'p',
    } satisfies ParserConfig
  }
} as const;